package com.jxb.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@RefreshScope
public class TestController {

    private static ApplicationContext applicationContext;

    @Autowired
    public void setApplicationContext(ApplicationContext applicationContext){
        TestController.applicationContext = applicationContext;
    }

    @Value("${user.name}")
    private String userName;

    @RequestMapping(value = "/testRun",method = RequestMethod.GET)
    public String testRun(){
        String result = "request is success";
        System.out.println("user:name======="+applicationContext.getEnvironment().getProperty("user.name"));
        System.out.println("nacos user name:=="+userName);
        int num=23;
        String newNum = String.format("Z%06d",num);
        System.out.println("newNum:"+newNum);
        return result;
    }
}
